# -*- coding: utf-8 -*-
from django import forms
from django.forms.widgets import SplitDateTimeWidget
from django.utils.safestring import mark_safe
from django.utils import formats

from django.utils.translation import ugettext_lazy as _


class CustomDateWidget(forms.DateInput):

    def __init__(self, attrs={}, format=None):
        f = '%d/%m/%Y'
        super(CustomDateWidget, self).__init__(attrs=attrs, format=f)

    def render(self, name, value, attrs=None):
        vdate = 'vDateField'
        attrs.update({'class': vdate, 'size': '10'})
        rend = super(CustomDateWidget, self).render(name=name, value=value, attrs=attrs)
        return rend


class CustomTimeWidget(forms.TimeInput):
    format = '%H:%M' # 23:59

    def __init__(self, attrs={}, format='%H:%M'):
        # format = format # formats.get_format('TIME_INPUT_FORMATS')[1]
        super(CustomTimeWidget, self).__init__(attrs=attrs, format=format)

    def render(self, name, value, attrs=None):
        vtime = 'vTimeField'
        attrs.update({'class': vtime, 'size': '8'})
        rend = super(CustomTimeWidget, self).render(name=name, value=value or '00:00', attrs=attrs)
        return rend


class DateTimeWidgetUI(SplitDateTimeWidget):

    def __init__(self, attrs=None):
        widgets = [CustomDateWidget, CustomTimeWidget]
        # Note that we're calling MultiWidget, not SplitDateTimeWidget, because
        # we want to define widgets.
        forms.MultiWidget.__init__(self, widgets, attrs)

    def format_output(self, rendered_widgets):
        return mark_safe(u'<p class="datetime">%s %s %s %s</p>' % \
            (_('Date:'), rendered_widgets[0], _('Time:'), rendered_widgets[1]))

    def decompress(self, value):
        if value:
            assert False, value
        return super(DateTimeWidgetUI, self).decompress(value)




